<?php
namespace wow\controller;


use \gnomephp\message\Message;
use \gnomephp\doctrine\Doctrine;



class Donation extends BaseController{

	public function __construct(){
		parent::__construct();
		$this->lang->load('donation');
	}
	
	
	public function index(){
		$conf = \gnomephp\Configuration::get('donation');
		
		
		
		if ($conf['enable']){

			
			
			if ($this->user){
				$charRealm = array();
				$realms = \wow\modelauth\Realmlist::getAllRealms();
				foreach($realms as $realm){
					$chars = $realm->getCharacters('account = ' . $this->user->getID());
					foreach($chars as $char){
						$charRealm[$realm->id][$char->guid] = $char->name; 
					}
				}
				$this->view->assign('charRealm', $charRealm);
			}
			
			
			$this->view->assign('donations', \wow\model\Donation::getDonations());
			
			$this->view->assign('donconfig', $conf);
				
			$this->view->render('donation/index');
		}else{
			Message::add(Message::ERROR, 'Donations is not enabled at this time.');
			$this->redirect($this->view->url->linkTo('Application','index'));
		}
		
	}
	
	public function thanks(){
		$conf = \gnomephp\Configuration::get('donation');
		
		$this->view->assign('donconfig', $conf);
		$this->view->render('donation/thanks');
	}
}